﻿using CrawlerFramework.Models;
using RakutenProxy.Model.Rakuten.Mapping;
using System.Data.Entity;

namespace RakutenProxy.Model.Rakuten
{
    public class RakutenDbContext : CrawlerDbContext
    {
        public DbSet<Category> Categories { get; set; }

        public DbSet<Manufacturer> Manufacturers { get; set; }

        public DbSet<ProductAttributeCombination> ProductAttributeCombinations { get; set; }

        public DbSet<ProductAttribute> ProductAttributes { get; set; }

        public DbSet<ProductAttributeValue> ProductAttributeValues { get; set; }

        public DbSet<Product_ProductAttribute_Mapping> Product_ProductAttribute_Mappings { get; set; }

        public DbSet<Product> Products { get; set; }

        public DbSet<Rakuten_NopCommerce_Product_Map> Rakuten_NopCommerce_Product_Maps { get; set; }

        public DbSet<Rakuten_NopCommerce_ProductAttribteValue_Map> Rakuten_NopCommerce_ProductAttribteValue_Maps { get; set; }

        public DbSet<Rakuten_NopCommerce_ProductAttribute_Map> Rakuten_NopCommerce_ProductAttribute_Maps { get; set; }

        public DbSet<Rakuten_NopCommerce_ProductAttributeCombination_Map> Rakuten_NopCommerce_ProductAttributeCombination_Maps { get; set; }

        public DbSet<Rakuten_NopCommerce_Product_ProductAttributeMapping_Map> Rakuten_NopCommerce_Product_ProductAttributeMapping_Maps { get; set; }

        public DbSet<Rakuten_NopCommerce_Category_Map> Rakuten_NopCommerce_Category_Maps { get; set; }

        public DbSet<Rakuten_NopCommerce_Manufacturer_Map> Rakuten_NopCommerce_Manufacturer_Maps { get; set; }

        public DbSet<Currency> Currencies { get; set; }

       
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Configurations.Add(new ProductMapping());
            modelBuilder.Configurations.Add(new CategoryMapping());
            modelBuilder.Configurations.Add(new ManufacturerMapping());
            modelBuilder.Configurations.Add(new ProductAttributeCombinationMapping());
            modelBuilder.Configurations.Add(new ProductAttributeMapping());
            modelBuilder.Configurations.Add(new ProductAttributeValueMapping());

            modelBuilder.Entity<Rakuten_NopCommerce_Category_Map>().HasKey(t => t.Id);
            modelBuilder.Entity<Rakuten_NopCommerce_Product_Map>().HasKey(t => t.Id);
            modelBuilder.Entity<Rakuten_NopCommerce_ProductAttribteValue_Map>().HasKey(t => t.Id);
            modelBuilder.Entity<Rakuten_NopCommerce_ProductAttribute_Map>().HasKey(t => t.Id);
            modelBuilder.Entity<Rakuten_NopCommerce_ProductAttributeCombination_Map>().HasKey(t => t.Id);
            modelBuilder.Entity<Rakuten_NopCommerce_Currency_Map>().HasKey(t => t.Id);
            modelBuilder.Entity<Rakuten_NopCommerce_Manufacturer_Map>().HasKey(t => t.Id);
           
            modelBuilder.Entity<Currency>().HasKey(t => t.CurrencyId);
        }
    }
}